#include "tcp_server.hpp"
#include "calculator.hpp"
#include <memory>

Calculator calculator; 

void OnMessage(std::weak_ptr<Connection> conn)
{
    if(conn.expired())
            return; 
    auto connection = conn.lock();
    // 处理信息 
    std::string response_str = calculator.Handler(connection->GetInbuffer());
    // std::cout << res << std::endl;
    
    // 把结果回应写入 输出缓冲区
    connection->AppendOutbuffer(response_str);
    // 发送
    connection->_write_cb(connection);
}

int main()
{
    std::shared_ptr<TcpServer> svr(new TcpServer(8888, OnMessage));
    svr->ServerInit();
    svr->Run();
        
    return 0;
}